package com.homework.exam02;

import com.homework.exam02.Event.NoticeListener02;
import javafx.application.Application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.*;

@SpringBootApplication
public class Exam02Application {

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(Application.class);
        application.addListeners(new NoticeListener02());
        SpringApplication.run(Exam02Application.class, args);
    }

}

@EnableAsync
@Configuration
class TaskThreadConfig{

    @Bean("taskThread")
    public Executor getAsyncExecutor(){
        ExecutorService taskThread = new ThreadPoolExecutor(
                2,
                10,
                2,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        return taskThread;
    }

}

